<?php

namespace App\Admin\Controllers;

use App\Services\IpAddresseService;
use Slowlyo\OwlAdmin\Controllers\AdminController;

/**
 * 运营商IP管理
 *
 * @property IpAddresseService $service
 */
class IpAddresseController extends AdminController
{
	protected string $serviceName = IpAddresseService::class;

	public function list()
	{
		$crud = $this->baseCRUD()
			->filterTogglable(false)
			->headerToolbar([
				$this->createButton('dialog'),
				...$this->baseHeaderToolBar()
			])
			->columns([
				amis()->TableColumn('id', 'ID')->sortable(),
				amis()->TableColumn('up_customer.short_name', '上游'),
				amis()->TableColumn('idcnode.idc_name', 'IDC机房'),
				amis()->TableColumn('upcustomer_bu.name', '业务期次'),
				amis()->TableColumn('ipType', 'IP类型'),
				amis()->TableColumn('addressBit', 'IP地址段'),
				amis()->TableColumn('startAddress', '开始IP'),
				amis()->TableColumn('endAddress', '结束IP'),
				amis()->TableColumn('upstreamCore', '上游核心'),
				amis()->TableColumn('created_at', admin_trans('admin.created_at'))->type('datetime')->sortable(),
				$this->rowActions('dialog')
			]);

		return $this->baseList($crud);
	}

	public function form($isEdit = false)
	{
		return $this->baseForm()->body([
			amis()->SelectControl('up_customer_id', '上游供应商')
					->searchable(true)
					->source('/up_customer?_action=getData')
					->labelField('short_name')
					->valueField('id')
					->autoFill([
						'type_id' => '${type_id}',
					]),
			amis()->SelectControl('idcnode_id', 'IDC机房')
					->searchable(true)
					->source('/idcnode?idc_belong=${type_id}&_action=getData')
					->labelField('idc_name')
					->valueField('id'),
			amis()->SelectControl('upcustomer_bu_id', '业务期次')
					->searchable(true)
					->source('/upcustomer_bus?_action=getData')
					->labelField('name')
					->valueField('id'),
			amis()->SelectControl('ipType', 'IP类型')->options([
				'1' => 'IPV4',
				'2' => 'IPV6',
			]),
			amis()->TextControl('addressBit', 'IP地址段'),
			amis()->TextControl('startAddress', '开始IP'),
			amis()->TextControl('endAddress', '结束IP'),
			amis()->TextControl('upstreamCore', '上游核心'),
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('up_customer.short_name', '上游')->static(),
			amis()->TextControl('idcnode.idc_name', 'IDC机房')->static(),
			amis()->TextControl('addressBit', 'IP地址段')->static(),
			amis()->TextControl('startAddress', '开始IP')->static(),
			amis()->TextControl('endAddress', '结束IP')->static(),
			amis()->TextControl('ipType', 'IP类型')->static(),
			amis()->TextControl('upstreamCore', '上游核心')->static(),
			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
			amis()->TextControl('operator.name', '操作人')->static(),
			

		]);
	}
}